﻿using AutoMapper;
using FluentValidation;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
using TL_Cloud.Core.Services;
using TL_Cloud.ViewModels.BookShop.BaseClass;
using TL_Cloud.ViewModels.BookShop.BaseGrade;
using TL_Cloud.ViewModels.BookShop.BaseStudent;
using TL_Cloud.ViewModels.BookShop.BaseSubject;
using TL_Cloud.ViewModels.BookShop.BaseTeacher;
using TL_Cloud.ViewModels.BookShop.BKInfo;
using TL_Cloud.ViewModels.BookShop.BKTypeInfo;

namespace TL_Cloud.ViewModels.BookShop
{
    /// <summary>
    /// 注册映射和验证
    /// </summary>
    public static class MapAndValidator
    {
        /// <summary>
        /// 注册映射
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddMap(this IServiceCollection services)
        {
            services.AddAutoMapper();
            return services;
        }
        /// <summary>
        /// 
        ///注册验证
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddValidator(this IServiceCollection services)
        {
            //注册LoginViewModel的验证
            services.AddTransient<IValidator<LoginViewModel>, LoginViewModelValidtor<LoginViewModel>>();

            //注册年级 的增加和修改
            services.AddTransient<IValidator<BaseGradeAddResource>, BaseGradeAddOrUpdateResourceValidator<BaseGradeAddResource>>();
            services.AddTransient<IValidator<BaseGradeUpdateResource>, BaseGradeAddOrUpdateResourceValidator<BaseGradeUpdateResource>>();

            //注册班级 的增加和修改
            services.AddTransient<IValidator<BaseClassAddResource>, BaseClassAddOrUpdateResourceValidator<BaseClassAddResource>>();
            services.AddTransient<IValidator<BaseClassUpdateResource>, BaseClassAddOrUpdateResourceValidator<BaseClassUpdateResource>>();

            //注册教师
            services.AddTransient<IValidator<BaseTeacherBasicInfoResource>, BaseTeacherAddOrUpdateResourceValidator<BaseTeacherBasicInfoResource>>();
            services.AddTransient<IValidator<BaseTeacherUpdateResource>, BaseTeacherAddOrUpdateResourceValidator<BaseTeacherUpdateResource>>();
            //注册学生
            services.AddTransient<IValidator<BaseStudentBasicInfoResource>, BaseStudentAddOrUpdateResourceValidator<BaseStudentBasicInfoResource>>();
            services.AddTransient<IValidator<BaseStudentUpdateResource>, BaseStudentAddOrUpdateResourceValidator<BaseStudentUpdateResource>>();
            //注册科目
            services.AddTransient<IValidator<BaseSubjectBasicResource>, BaseSubjectAddOrUpdateResourceValidator<BaseSubjectBasicResource>>();
            services.AddTransient<IValidator<BaseSubjectUpdateResource>, BaseSubjectAddOrUpdateResourceValidator<BaseSubjectUpdateResource>>();
            //注册图书类型
            services.AddTransient<IValidator<BKTypeBasicResource>, BKTypeInfoAddOrUpdateResourceValidator<BKTypeBasicResource>>();
            services.AddTransient<IValidator<BKTypeUpdateResource>, BKTypeInfoAddOrUpdateResourceValidator<BKTypeUpdateResource>>();

            //注册图书
            services.AddTransient<IValidator<BKInfoBasicResource>, BKInfoAddOrUpdateResourceValidator<BKInfoBasicResource>>();
            services.AddTransient<IValidator<BKInfoUpdateResource>, BKInfoAddOrUpdateResourceValidator<BKInfoUpdateResource>>();


            return services;
        }
        /// <summary>
        /// 增加属性映射容器
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddMappingContainer(this IServiceCollection services)
        {
            var propertyMappingContainer = new PropertyMappingContainer();

            propertyMappingContainer.Register<BaseClassPropertyMapping>();
            propertyMappingContainer.Register<GradePropertyMapping>();
            propertyMappingContainer.Register<BaseTeacherPropertyMapping>();
            propertyMappingContainer.Register<BaseStudentPropertyMapping>();
            propertyMappingContainer.Register<BaseSubjectPropertyMapping>();

            propertyMappingContainer.Register<BKTypeInfoPropertyMapping>();
            propertyMappingContainer.Register<BKInfoPropertyMapping>();

            services.AddSingleton<IPropertyMappingContainer>(propertyMappingContainer);
            return services;
        }
    }
}
